<?php
uses('Flay');
uses("sanitize");

if(!isset($full_description))
{
    if(!isset($this->params['named']['full_description']))
    {
        $full_description = false;
    }
    else
    {
        $full_description = $this->params['named']['full_description'];
    }
}

//$isModuleRender - flag that it's module element render.
if (!isset($isModuleRender)) {
    $isModuleRender = false;
}
$reviewConfig = cr('ReviewConfig');
$presentUrl   = $this->params['controller'] . '-' . $this->params['action'];
if ($isModuleRender == true) {
    $presentUrl = "";
}
$showVotes        = true;
$showOtherLinks   = true;
$showCustomFields = false;
if (!isset($showAvatar)) {
    $showAvatar = false;
}
if ($isModuleRender == false && ($presentUrl == 'reviews-view' || (isset($this->params['pass']['0']) && $this->params['pass']['0'] == 'listing'))) {
    $showAvatar       = true;
    $showCustomFields = true;
}
$authedUserId = $session->read('Auth.User.id');
if (!isset($this->Review)) {
    $this->Review = cri('Review');
    $this->Review->setScope('published');
}

//code to set css class name starts here
$themeClass     = $view_type;
$containerClass = '';
if ($view_type == 'table_view') {
    $themeClass     = 'table_view';
    $containerClass = 'table_view_container';
}
//code to set css class name ends here
?>

<?php
if (empty($reviews)) {
    echo "<h4 class='no_results'>" . __("No reviews found!") . "</h4>";
} else {
?><ul><?php
    foreach ($reviews as $review) {
        $reviewClass = "";
        if (isset($review['Review']['is_featured']) && $review['Review']['is_featured'] == 1) {
            $reviewClass = "featured";
        }
?>
       <!--@todo (1.1) Remove class table_view_container when blog view enabled for review index -->
        <li>


        <div class="reviewBox <?php
        echo $reviewClass . ' ' . $containerClass;
?>" style="">
            <div class="<?php
        echo $themeClass;
?>">
<?php if (!$showAvatar) { ?>
                <div class="img">
                    <?php
        echo $html->link($html->image($review['Listing']['image'], array(
            'thumb' => array(
                'crop' => true,
                'width' => 97,
                'height' => 65
            )
        )), $review['Listing']['viewUrl'], array(
            'escape' => false
        ));
?>
               </div>
<?php } ?>
                <?php
        if ($showAvatar) {
?>
                   <div class="poster_info">
                    <?php
            if ($review['Review']['poster_entity'] == 'Guest') {
?>
                           <?php
                echo $html->image($review['Review']['poster']['avatar'], array(
                    "thumb" => array(
                        'height' => "65",
                        'width' => "97"
                    )
                ));
?>    
                            <?php
                echo $review['Review']['poster']['display_name'];
?>
                       
                        <?php
            } else {
?>
                           <?php
                echo $html->link($html->image($review['Review']['poster']['avatar'], array(
                    "thumb" => array(
                        'height' => "65",
                        'width' => "97"
                    )
                )), $review['Review']['poster']['profile_url'], array(
                    'escape' => false,
                    'title' => $review['Review']['poster']['display_name'],
                    'class' => 'poster'
                ));
?>
                           <?php
                echo $html->link($review['Review']['poster']['display_name'], $review['Review']['poster']['profile_url'], array(
                    'class' => 'poster'
                ));
?>
                       <?php
            }
?>
               </div>
                <?php
        }
?>
               <div class="desc">
                                            <?php
                        if ($presentUrl != 'reviews-view')
                        {?>
                                            <div class="rbox">
                                            
                                            <?php echo $html->link("Read full", $review['Review']['viewUrl'], array('class' => "view_details")); ?>

                                                <span> <?php if ($reviewConfig['allow_comment'])
                            {
                                echo sprintf(__('%d Comments'), $review['Review']['review_comment_count']);
                            }?></span>
                                            </div><?php
                                                                            }?>

                                            <div class="desc_l">                                            
                                               <h3><?php echo $html->link($review['Listing']['title'],$review['Listing']['viewUrl'])?>
</h3>
                                                <p>Added by: 
                                                <?php
        if ($review['Review']['poster_entity'] == 'Guest') {
?>
                           <?php
            echo $review['Review']['poster']['display_name'];
?>
                       
                        <?php
        } else {
?>
                           <?php
            echo $html->link($review['Review']['poster']['display_name'], $review['Review']['poster']['profile_url'], array(
                'class' => 'poster'
            ));
?>
                       <?php
        }
?>

                        <?php
        echo $time->timeAgoInwords($review['Review']['created'], array(
            'shortString' => true
        ));
?></p>
    <?php
                        if(!isset($reviewInformation))
                        {
                            $html->initHelper("ReviewInformation");
                            $reviewInformation = $html->ReviewInformation;
                         }
                        
                        ?>
                    <?php
                      echo $reviewInformation->showAverageRating($review,__(""));
                    ?>                  
                                            </div>  
                                   </div>

    <div class="detail">
                                            <h5><?php echo $html->link($review['Review']['title'],$review['Review']['viewUrl']);?></h5>
        <p><?php
            $reviewBody = $review['Review']['body'];
            $reviewBody = strip_tags($review['Review']['body']);
            $reviewBody = str_replace(array("\n",), " ", $reviewBody);
            $reviewBody = Flay::fragment($reviewBody, 180);
            echo $reviewBody;
            ?>
        </p>
    </div>
                

            </div>
        </div>
    <?php
    } //foreach ends here
} //main if block ends here.
?>
</li>
</ul>
<div class="clear"></div>